package com.tbk.wechatbot.robot;

import com.tbk.wechatbot.service.TpwdService;
import io.github.biezhi.wechat.WeChatBot;
import io.github.biezhi.wechat.api.annotation.Bind;
import io.github.biezhi.wechat.api.constant.Config;
import io.github.biezhi.wechat.api.enums.MsgType;
import io.github.biezhi.wechat.api.model.WeChatMessage;
import io.github.biezhi.wechat.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class TpwdRobot extends WeChatBot {

    @Autowired
    private TpwdService tpwdService;

    public TpwdRobot(Config config) {
        super(config);
    }

    @Bind(msgType = MsgType.TEXT)
    public void handleText(WeChatMessage message) throws InterruptedException {
        if (StringUtils.isNotEmpty(message.getName())) {
            List<String> tpwdList = tpwdService.getMaterialTpwd(message.getText());
            if (tpwdList == null) {
                this.sendMsg(message.getFromUserName(), "没有查询到优惠券信息！");
                return;
            }
            for (int i = 0; i < tpwdList.size(); i++) {
                this.sendMsg(message.getFromUserName(), tpwdList.get(i));
//                Thread.sleep(1000);
            }
            return;
        }
    }


    public void replyText(WeChatMessage message, String msg) {
        this.sendMsg(message.getFromUserName(), msg);
    }

}
